<template>
  <div class="app-container">
    <div class="project-list-view">
      <el-table :data="tableData3"
                border
                style="width: 100%"
                :row-key="tableData3.id">
        <el-table-column prop="id"
                         label="ID"
                         width="100">
        </el-table-column>
        <el-table-column prop="tagName"
                         label="标签名">
        </el-table-column>

        <el-table-column prop="username"
                         label="添加人"
                         width="100">
        </el-table-column>
        <el-table-column prop="delete"
                         label="删除"
                         width="80">
          <template slot-scope="scope">
            <el-button @click="handleDelete(scope.$index)"
                       type="danger"
                       plain
                       size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import {
  getProjectList,
  updateProjectSelected,
  updateProjectHot,
  delProject,
} from '@/api/projectList'
export default {
  name: 'ProjectList',
  computed: {},
  data() {
    return {
      tableData3: [],
      projectSelected: '0',
      projectHot: '0',
    }
  },
  methods: {
    // 获取项目信息
    getProjectInfo: function () {
      // return getProjectList().then((res) => {
      //   this.tableData3.splice(0, this.tableData3.length)
      //   this.tableData3.push(...res.data.rows)
      // })
      // this.tableData3.splice(0, this.tableData3.length)
      this.tableData3 = [
        {
          id: 1,
          tagName: '前端',
          username: 'admin',
        },
        {
          id: 2,
          tagName: 'Vue',
          username: 'admin',
        },
        {
          id: 3,
          tagName: 'React',
          username: 'admin',
        },
        {
          id: 4,
          tagName: 'TypeScript',
          username: 'admin',
        },
        {
          id: 5,
          tagName: '后端',
          username: 'admin',
        },
        {
          id: 6,
          tagName: 'Java',
          username: 'admin',
        },
        {
          id: 7,
          tagName: 'SpringBoot',
          username: 'admin',
        },
        {
          id: 8,
          tagName: 'Python',
          username: 'admin',
        },
      ]
    },
    // // 根据项目文件地址下载项目文件
    // handleDownloadProject: function (url) {
    //   console.log('download', JSON.parse(url))
    // },
    // // 项目设置按钮，初始化内部所需参数
    // handleSetting: function (info) {
    //   let selected = info.selected.toString()
    //   let hot = info.hot.toString()
    //   this.projectSelected = selected
    //   this.projectHot = hot
    // },
    // 删除项目
    handleDelete: function (index) {
      console.log('删除')
          this.tableData3.splice(index, 1)
          // this.tableData3.length = 
      this.$message({
        showClose: true,
        message: '标签删除成功',
        type: 'success',
      })
      // delProject({id:id}).then((res) => {
      //   if (res.data.status === 200) {
      //     this.$message({
      //       showClose: true,
      //       message: res.data.data,
      //       type: 'success',
      //     }),
      //       this.getProjectInfo()
      //   }
      // })
    },
    // 项目精选开关
    handleChangeSelected: function (projectId) {
      updateProjectSelected({
        pro_id: projectId,
        selected: this.projectSelected,
      }).then((res) => {
        if (res.data.status == 200) {
          this.$message({
            showClose: true,
            message: res.data.data,
            type: 'success',
          }),
            this.getProjectInfo()
        } else {
          this.$message({
            showClose: true,
            message: res.data.data,
            type: 'warning',
          })
        }
      })
    },
    // 项目热门开关
    handleChangeHot: function (projectId) {
      updateProjectHot({
        pro_id: projectId,
        hot: this.projectHot,
      }).then((res) => {
        if (res.data.status == 200) {
          this.$message({
            showClose: true,
            message: res.data.data,
            type: 'success',
          }),
            this.getProjectInfo()
        } else {
          this.$message({
            showClose: true,
            message: res.data.data,
            type: 'warning',
          })
        }
      })
    },
  },
  beforeMount() {
    this.getProjectInfo()
  },
}
</script>

<style lang="scss"></style>